package com.sb.registration.component.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * User Registration Service Result Object that will provide data as requested by other 
 * applications or error details in case of exceptions or failure in executing request.
 * 
 *  * NOTE - ERROR CODES AND MESSAGES CAN BE MOVED TO PROPERTIES FILE, HARCODING HERE FOR QUICK CODING
 * 
 * ERROR CODE 101 ---> USER DOES NOT EXIST
 * ERROR CODE 102 ---> SYSTEM ERROR
 * ERROR CODE 103 ---> USER ALREADY REGISTERED
 * 
 * @author gautam.amitkumar@gmail.com
 *
 */
@XmlRootElement
public class UserRegistrationServiceResult implements Serializable {
	
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -5856298359038036527L;
	
	public static final String SUCCESS = "Success";
	
	public static final String FAILURE = "Failure";
	
	public static Map<Integer, String> errorMap = new HashMap<Integer, String>();
	
	public UserRegistrationServiceResult(){
		errorMap.put(101, "User does not exist in the system.");
		errorMap.put(102, "System Error, Please try again after some time.");
		errorMap.put(103, "User already registered in the system with the given email id.");
		errorMap.put(104, "User Details Not Valid <br/><br/>");
		errorMap.put(105, "");
		
	}
	
	/**
	 * Field to hold status of service method request.
	 */
	private String status = FAILURE;

	/**
	 * Field to hold user data. It will be null in case of any error.
	 */
	private UserWrapper userData;
	
	/**
	 * Field to hold user list. It will be null in case of any error.
	 */
	private List<UserWrapper> userList;
	
	/**
	 * Field to hold error details. It will be null in case of no errors.
	 */
	private ErrorDetails errorDetails;

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public UserWrapper getUserData() {
		return userData;
	}

	public void setUserData(UserWrapper userData) {
		this.userData = userData;
	}

	public List<UserWrapper> getUserList() {
		return userList;
	}

	public void setUserList(List<UserWrapper> userList) {
		this.userList = userList;
	}

	public ErrorDetails getErrorDetails() {
		return errorDetails;
	}

	public void setErrorDetails(ErrorDetails errorDetails) {
		this.errorDetails = errorDetails;
	}

	@Override
	public String toString() {
		return "UserRegistrationServiceResult [userData=" + userData
				+ ", userList=" + userList + ", errorDetails=" + errorDetails
				+ "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((errorDetails == null) ? 0 : errorDetails.hashCode());
		result = prime * result
				+ ((userData == null) ? 0 : userData.hashCode());
		result = prime * result
				+ ((userList == null) ? 0 : userList.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserRegistrationServiceResult other = (UserRegistrationServiceResult) obj;
		if (errorDetails == null) {
			if (other.errorDetails != null)
				return false;
		} else if (!errorDetails.equals(other.errorDetails))
			return false;
		if (userData == null) {
			if (other.userData != null)
				return false;
		} else if (!userData.equals(other.userData))
			return false;
		if (userList == null) {
			if (other.userList != null)
				return false;
		} else if (!userList.equals(other.userList))
			return false;
		return true;
	}
	
	

}
